<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>修改密码 - 银行管理系统</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css">
    <style>
        body {
            font-family: "Microsoft YaHei", sans-serif;
            background-color: #f5f5f5;
        }
        .main-container {
            display: flex;
            min-height: 100vh;
        }
        .sidebar {
            width: 250px;
            background-color: #0d47a1;
            color: #fff;
            padding-top: 20px;
        }
        .sidebar .nav-link {
            color: #fff;
            padding: 10px 20px;
            border-left: 3px solid transparent;
        }
        .sidebar .nav-link:hover {
            background-color: #1565c0;
            border-left: 3px solid #fff;
        }
        .sidebar .nav-link.active {
            background-color: #1976d2;
            border-left: 3px solid #fff;
        }
        .sidebar .nav-link i {
            margin-right: 10px;
        }
        .content {
            flex: 1;
            padding: 20px;
            background-color: #fff;
        }
        .header {
            background-color: #1976d2;
            color: #fff;
            padding: 15px 20px;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        .header h1 {
            margin: 0;
            font-size: 1.5rem;
        }
        .card {
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            margin-bottom: 20px;
        }
        .card-header {
            background-color: #1976d2;
            color: #fff;
            border-radius: 8px 8px 0 0 !important;
        }
    </style>
</head>
<body>
    <div class="main-container">
        <div class="sidebar">
            <div class="text-center mb-4">
                <h3>银行管理系统</h3>
            </div>
            <ul class="nav flex-column">
                <li class="nav-item">
                    <a class="nav-link" href="/client/card/index">
                        <i class="fa fa-dashboard"></i> 控制台
                    </a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="/client/card/balance">
                        <i class="fa fa-search"></i> 余额查询
                    </a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="/client/card/deposit">
                        <i class="fa fa-plus-circle"></i> 存款
                    </a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="/client/card/withdraw">
                        <i class="fa fa-minus-circle"></i> 取款
                    </a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="/client/card/transfer">
                        <i class="fa fa-exchange"></i> 转账
                    </a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="/client/card/transactions">
                        <i class="fa fa-list"></i> 交易记录
                    </a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="/client/card/report-loss">
                        <i class="fa fa-lock"></i> 挂失/解挂
                    </a>
                </li>
                <li class="nav-item">
                    <a class="nav-link active" href="/client/card/change-password">
                        <i class="fa fa-key"></i> 修改密码
                    </a>
                </li>
                <li class="nav-item mt-5">
                    <a class="nav-link" href="/">
                        <i class="fa fa-sign-out"></i> 退出系统
                    </a>
                </li>
            </ul>
        </div>
        
        <div class="flex-grow-1 d-flex flex-column">
            <div class="header">
                <h1>修改密码</h1>
                <div class="d-flex align-items-center">
                    <span>欢迎，客户</span>
                </div>
            </div>
            
            <div class="content">
                <div id="alertContainer"></div>
                
                <div class="row justify-content-center">
                    <div class="col-md-8">
                        <div class="card">
                            <div class="card-header">
                                <h5 class="mb-0">修改银行卡密码</h5>
                            </div>
                            <div class="card-body">
                                <form id="changePasswordForm">
                                    <div class="form-group">
                                        <label for="cardId">银行卡号</label>
                                        <input type="text" class="form-control" id="cardId" name="cardId" placeholder="请输入银行卡号" required>
                                    </div>
                                    
                                    <div class="form-group">
                                        <label for="oldPassword">原密码</label>
                                        <input type="password" class="form-control" id="oldPassword" name="oldPassword" placeholder="请输入原密码" required>
                                    </div>
                                    
                                    <div class="form-group">
                                        <label for="newPassword">新密码</label>
                                        <input type="password" class="form-control" id="newPassword" name="newPassword" placeholder="请输入新密码" required>
                                    </div>
                                    
                                    <div class="form-group">
                                        <label for="confirmPassword">确认新密码</label>
                                        <input type="password" class="form-control" id="confirmPassword" name="confirmPassword" placeholder="请再次输入新密码" required>
                                    </div>
                                    
                                    <div class="text-center">
                                        <button type="submit" class="btn btn-primary btn-lg px-5">确认修改</button>
                                    </div>
                                </form>
                            </div>
                        </div>
                        
                        <div class="card mt-4">
                            <div class="card-header">
                                <h5 class="mb-0">密码修改须知</h5>
                            </div>
                            <div class="card-body">
                                <ul class="mb-0">
                                    <li>密码长度必须为6位数字</li>
                                    <li>新密码不能与原密码相同</li>
                                    <li>请确保输入正确的原密码</li>
                                    <li>密码修改成功后，请妥善保管新密码</li>
                                    <li>如有疑问，请联系银行客服：400-123-4567</li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js"></script>
    <script>
        // 通用提示框
        function showAlert(message, type) {
            const alertDiv = $('<div class="alert alert-' + type + ' alert-dismissible fade show" role="alert">' +
                message +
                '<button type="button" class="close" data-dismiss="alert" aria-label="Close">' +
                '<span aria-hidden="true">&times;</span>' +
                '</button>' +
                '</div>');
            
            $('#alertContainer').html(alertDiv);
            
            setTimeout(function() {
                alertDiv.alert('close');
            }, 3000);
        }
        
        $(document).ready(function() {
            // 表单提交
            $('#changePasswordForm').submit(function(e) {
                e.preventDefault();
                
                const cardId = $('#cardId').val().trim();
                const oldPassword = $('#oldPassword').val().trim();
                const newPassword = $('#newPassword').val().trim();
                const confirmPassword = $('#confirmPassword').val().trim();
                
                if (!cardId) {
                    showAlert('请输入银行卡号', 'warning');
                    return;
                }
                
                if (!oldPassword) {
                    showAlert('请输入原密码', 'warning');
                    return;
                }
                
                if (!newPassword) {
                    showAlert('请输入新密码', 'warning');
                    return;
                }
                
                if (newPassword.length !== 6 || !/^\d{6}$/.test(newPassword)) {
                    showAlert('新密码必须为6位数字', 'warning');
                    return;
                }
                
                if (newPassword === oldPassword) {
                    showAlert('新密码不能与原密码相同', 'warning');
                    return;
                }
                
                if (newPassword !== confirmPassword) {
                    showAlert('两次输入的新密码不一致', 'warning');
                    return;
                }
                
                // 提交修改密码请求
                $.ajax({
                    url: '/client/card/do-change-password',
                    type: 'POST',
                    data: {
                        cardId: cardId,
                        oldPassword: oldPassword,
                        newPassword: newPassword
                    },
                    success: function(res) {
                        if (res.code === 200) {
                            showAlert('密码修改成功', 'success');
                            $('#changePasswordForm')[0].reset();
                        } else {
                            showAlert(res.message || '密码修改失败', 'danger');
                        }
                    },
                    error: function() {
                        showAlert('网络错误，请稍后重试', 'danger');
                    }
                });
            });
        });
    </script>
</body>
</html> 